<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Api\Controller;

use Utils\Image;

class UploadController extends BaseController {

    public function uploadImage() {
        $file = $_FILES;
        $result = ['code' => "99999", "msg" => "未知错误  "];
        if ($file["file"]["error"] == "0") {
            $imgPath = Image::uploadImage($file["file"]["tmp_name"]);
            $result = ['code' => "10000", "msg" => "sucess", "imagePath" => C("STATIC_IMG") . $imgPath];
        } else if ($file["file"]["error"] == "4") {
            $result = ["code" => "10001", "msg" => "没有文件上传"];
        } else if ($file["file"]["error"] == "6") {
            $result = ["code" => "10002", "msg" => "找不到临时文件"];
        } else {
            $result = ["code" => "10004", "msg" => "图片上传失败"];
        }
        exit(json_encode($result));
    }

}
